using System.Collections.Generic;

namespace Flit.Samples.GivenWhenThen
{
    public abstract class FluentStateBase
    {
        protected FluentStateBase()
        {
            Children = new List<FluentStateBase>();
        }

        public FluentStateBase Parent { get; set; }

        public List<FluentStateBase> Children { get; private set; }

        public abstract void VisitCallback(IFragmentVisitor v);

        public IEnumerable<FluentStateBase> Ancestors()
        {
            FluentStateBase f = this;
            while(f != null)
            {
                yield return f;
                f = f.Parent;
            }
        }

        public IEnumerable<FluentStateBase> Descendants()
        {
            foreach (var c in Children)
            {
                yield return c;
                foreach (var gc in c.Descendants())
                {
                    yield return gc;
                }
            }
        }
    }
}